//
//  MQDetailCellOfFind.m
//  MinDyNews
//
//  Created by ZMQ on 16/7/21.
//  Copyright © 2016年 MQ. All rights reserved.
//

#import "MQDetailCellOfFind.h"
#import "MQSamllModelOfFind.h"

@interface MQDetailCellOfFind ()

@property (nonatomic, retain) UIImageView *imageViewOfcover;//图片
@property (nonatomic, retain) UILabel *labelOftitle;//标题
@property (nonatomic, retain) UILabel *labelOfcategory;//创意类型
@property (nonatomic, retain) UILabel *labelOfduration;//时间
@property (nonatomic, retain) UIView *viewOfLine;//分区线
@property (nonatomic, retain) UIView *viewOfShadow;//加暗度，让标题显现，高亮


@end


@implementation MQDetailCellOfFind



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self customsubview];
        
    }
    return  self;
    
}

-(void)customsubview{
    
    self.imageViewOfcover = [[UIImageView alloc]init];
    [self.contentView addSubview:_imageViewOfcover];
    
    [self.imageViewOfcover mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.equalTo(self);
        
    }];

    
    
    self.viewOfShadow = [[UIView alloc]init];
    [self.imageViewOfcover addSubview:_viewOfShadow];
    self.viewOfShadow.backgroundColor = [UIColor colorWithRed:38 / 255.0 green:38 / 255.0 blue:38 / 255.0 alpha:0.2];
    [self.viewOfShadow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(self.imageViewOfcover);
        
    }];

    
    
    self.labelOftitle = [[UILabel alloc]init];
    [self.viewOfShadow addSubview:_labelOftitle];
    self.labelOftitle.textColor = [UIColor whiteColor];
    self.labelOftitle.textAlignment = UIBaselineAdjustmentAlignCenters;
    self.labelOftitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    
    [self.labelOftitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.viewOfShadow);
        make.centerY.equalTo(self.viewOfShadow);
        make.width.equalTo(self.viewOfShadow);
        make.height.offset(20);
        
    }];   
    
    
    self.viewOfLine = [[UIView alloc]init];
    [self.viewOfShadow addSubview:_viewOfLine];
    self.viewOfLine.backgroundColor = [UIColor whiteColor];
    
    [self.viewOfLine mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.labelOftitle.mas_bottom).with.offset(5);
        make.centerX.equalTo(self.viewOfShadow);
        make.width.offset(0);
        make.height.offset(0);
        
    }];
    
    
    self.labelOfcategory = [[UILabel alloc]init];
    [self.viewOfShadow addSubview:_labelOfcategory];
    self.labelOfcategory.textColor = [UIColor whiteColor];
//        self.labelOfcategory.backgroundColor = [UIColor redColor];
    self.labelOfcategory.font = [UIFont systemFontOfSize:11];
    [self.labelOfcategory mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.labelOftitle.mas_bottom).with.offset(5);
        make.right.equalTo(self.viewOfLine.mas_left).with.offset(-10);
        make.width.offset(30);
        make.height.offset(15);
        
    }];

    /////
    /////
    /////
    
    
    
    self.labelOfduration = [[UILabel alloc]init];
    [self.viewOfShadow addSubview:_labelOfduration];
    self.labelOfduration.font = [UIFont systemFontOfSize:11];
    self.labelOfduration.textColor = [UIColor whiteColor];
//        self.labelOfduration.backgroundColor = [UIColor grayColor];
    [self.labelOfduration mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.labelOftitle.mas_bottom).with.offset(5);
        make.left.equalTo(self.viewOfLine.mas_right);
        make.width.offset(60);
        make.height.offset(15);
        
    }];
 
    
}


-(void)setModel:(MQSamllModelOfFind *)model{
    
    _model = model;
    if ([model.type isEqualToString:@"banner2"]) {
        
         NSURL *url = [NSURL URLWithString:[model.data objectForKey:@"image"]];
        [self.imageViewOfcover sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"ZMQ"]];
    
    
    }else{
        
        //图片
        NSURL *url = [NSURL URLWithString:[[model.data objectForKey:@"cover"]objectForKey:@"feed"]];
        [self.imageViewOfcover sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"ZMQ"]];
        
        //标题
        self.labelOftitle.text = [model.data objectForKey:@"title"];
        
        //创意类型
        
        self.labelOfcategory.text = [NSString stringWithFormat:@"#%@", [model.data objectForKey:@"category"]];
        
        
        //时间
        NSInteger time = [[model.data objectForKey:@"duration"] integerValue];
        NSInteger minute = time / 60;
        NSInteger second = time % 60;
        
        self.labelOfduration.text = [NSString stringWithFormat:@"/   %ld分%ld秒", (long)minute, (long)second] ;
        
        
    }
    
}

    
    
    


@end
